<template>
  <div id="total">
      <el-table
        :data="scoreTotal"
        style="width: 50%;float: left"
        max-height="100%">
        <el-table-column
          fixed
          prop="userId"
          label="用户id"
          width="150">
        </el-table-column>
        <el-table-column
          label="表现"
          width="400">
          <el-tag>标签一</el-tag>
          <el-tag type="success">标签二</el-tag>
          <el-tag type="info">标签三</el-tag>
          <el-tag type="warning">标签四</el-tag>
          <el-tag type="danger">标签五</el-tag>
        </el-table-column>
        <el-table-column
          fixed="right"
          prop="number"
          label="总分"
          width="120">
        </el-table-column>
      </el-table>
    <el-table
      :data="scoreTotal"
      style="width: 50%;float:right"
      max-height="100%"
      >
      <el-table-column
        fixed
        prop="userId"
        label="用户id"
        width="150">
      </el-table-column>
      <el-table-column
        label="表现"
        width="400">
        <el-tag>标签一</el-tag>
        <el-tag type="success">标签二</el-tag>
        <el-tag type="info">标签三</el-tag>
        <el-tag type="warning">标签四</el-tag>
        <el-tag type="danger">标签五</el-tag>
      </el-table-column>
      <el-table-column
        fixed="right"
        prop="number"
        label="总分"
        width="120">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {countNumber} from "@/api/ins/integral"
export default {
  name: 'Total',
  data() {
    return {
      tableData: [],
      scoreTotal: []
    }
  },
  created() {
    this.countNumberShow()
  },
  methods: {
    countNumberShow() {
      countNumber().then(result => {
        console.log(result)
        this.tableData = result.data
        let obj = {}
        this.tableData.forEach(v=>{
          if (obj.hasOwnProperty(v.userId)) {
            obj[v.userId] += v.number
          } else {
            obj [v.userId] = v.number
          }
        })
        console.log(obj)
        let obj2 ;
        for (let i in obj) {
          obj2 = {}
          obj2.userId = i;//i是属性名，也就是我们常说的key
          obj2.number = obj[i];//objs[i]是属性值，也就是我们常说的value
          this.scoreTotal.push(obj2);
        }
      })
    }
  }
}
</script>


